

** Change the directory

** Open Dataset
** As of 2019, the dataset is available for download at this site: https://www.pewresearch.org/global/dataset/spring-2017-survey-data/
use "Pew2017.dta", clear


** Keep Responents from the Countries in the Study
keep if Country==8 | Country==11 | Country==15 | Country==21 | Country==31

** Replace missing values with "."
** Flip scale so 4==Best ... 1=Worst
foreach country in Germany Britain EU US China Russia {
	rename fav_`country' `country'
	replace `country'=. if `country'==5 | `country'==6
	replace `country'=abs(`country'-5)
	}

summarize US Germany Britain EU  China Russia

** Create confidence Interval plots

** Install to create plot
* ssc install ciplot

#delimit;
ciplot   Germany Britain EU US China Russia,
yscale(range(1 4.5))
ylabel( 1 `" "Very" "Unfavorable" "' 2 `" "Somewhat"  "Unfavorable" "' 
3 `" "Somewhat" "Favorable" "' 4 `" "Very" "Favorable" "', labsize(small))
xlabel (2 "Germany" 4 "Britain" 6 "The EU" 8 "The US" 10 "China" 12 "Russia")
title("Please tell me if you have a very favorable," "somewhat favorable, somewhat unfavorable" "or very unfavorable opinion of..." )
msymbol(i i i i i i) 
graphregion(fcolor(white) ifcolor(white));
#delimit cr
	** Export Graph
	gr export PewAttitudes.png, replace

	
** Create Graph with Results by Country of Resident
#delimit;
ciplot   Germany Britain EU US China Russia,
by(Country)
rcapopts(lcolor(white))
yscale(range(1 4.5))
ylabel( 1 `" "Very" "Unfavorable" "' 2 `" "Somewhat"  "Unfavorable" "' 
3 `" "Somewhat" "Favorable" "' 4 `" "Very" "Favorable" "', labsize(small))
title("Please tell me if you have a very favorable," "somewhat favorable, somewhat unfavorable" "or very unfavorable opinion of..." )
xtitle(Respondents' Country)
msymbol(T  +  Oh  D  X  Sh)
mcolor(black black black black black black)
legend(row(1) 
label(2 "Germany") label(3 "Britain") label(4 "The EU") 
label(5 "The US") label(6 "China") label(7 "Russia")
position(12))
note(" ")
graphregion(fcolor(white) ifcolor(white));
#delimit cr
	** Export Graph
	gr export PewAttitudes-Countries.png, replace
